unit uNaszeMarki;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Db, ADODB;

type
  TFNaszeMarki = class(TForm)
    BitBtn1: TBitBtn;
    ListBox1: TListBox;
    ListBox2: TListBox;
    qTemp: TADOQuery;
    btDodaj: TButton;
    btUsun: TButton;
    procedure FormShow(Sender: TObject);
    procedure btDodajClick(Sender: TObject);
    procedure btUsunClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    BazaDyn : string;
  end;

var
  FNaszeMarki: TFNaszeMarki;

implementation

{$R *.DFM}

uses Wilk;

procedure TFNaszeMarki.FormShow(Sender: TObject);
begin
  SQLOpen(qTemp, 'SELECT Opis FROM '+BazaDyn+'..TW_SLOWNIK WHERE [Kod]=200');
  while not qTemp.Eof do
  begin
    ListBox2.Items.Add(trim(qTemp.Fields[0].AsString));
    qTemp.Next;
  end;
  SQLOpen(qTemp, 'SELECT MArka FROM TW_wMarka WHERE Marka not in (SELECT Opis FROM '
            +BazaDyn+'..TW_SLOWNIK WHERE [Kod]=200)');
  while not qTemp.Eof do
  begin
    ListBox1.Items.Add(trim(qTemp.Fields[0].AsString));
    qTemp.Next;
  end;
  
end;

procedure TFNaszeMarki.btDodajClick(Sender: TObject);
begin
  if ListBox1.ItemIndex<>-1 then
  begin
    ListBox2.Items.Add(ListBox1.Items[ListBox1.ItemIndex]);

    SQLExec(qTemp, 'INSERT '+BazaDyn+'..TW_SLOWNIK ([Kod], Opis) VALUES(200, '''+
       ListBox1.Items[ListBox1.ItemIndex]+''')');
    ListBox1.Items.Delete(ListBox1.ItemIndex);
  end;
end;

procedure TFNaszeMarki.btUsunClick(Sender: TObject);
begin
  if ListBox2.ItemIndex<>-1 then
  begin
    ListBox1.Items.Add(ListBox2.Items[ListBox2.ItemIndex]);
    SQLExec(qTemp, 'DELETE FROM '+BazaDyn+'..TW_SLOWNIK WHERE [Kod]=200 and Opis='''+
        ListBox2.Items[ListBox2.ItemIndex]+'''');
    ListBox2.Items.Delete(ListBox2.ItemIndex);
  end;
end;

end.
